export interface SchoolConfig {
    grades: number; // 年级数量
    minClassesPerGrade: number; // 每个年级最少班级数
    maxClassesPerGrade: number; // 每个年级最多班级数
    minStudentsPerClass: number; // 每个班级最少学生数
    maxStudentsPerClass: number; // 每个班级最多学生数
    minStudentValue: number; // 学生 value 最小值
    maxStudentValue: number; // 学生 value 最大值
}

export function generateSchoolData(config: SchoolConfig): any {
    const schoolData: any = {
        name: "阳光小学",
        children: [],
    };

    // 生成年级
    for (let g = 0; g < config.grades; g++) {
        const gradeIndex = g + 1;
        const gradeName = `${gradeIndex}年级`;
        const grade: any = {
            name: gradeName,
            children: [],
        };

        // 为每个年级生成班级
        const classCount = getRandomIntBetween(
            config.minClassesPerGrade,
            config.maxClassesPerGrade
        );

        for (let c = 0; c < classCount; c++) {
            const className = `${c + 1}班`;
            const classData: any = {
                name: className,
                children: [],
            };

            // 为每个班级生成学生
            const studentCount = getRandomIntBetween(
                config.minStudentsPerClass,
                config.maxStudentsPerClass
            );

            for (let s = 0; s < studentCount; s++) {
                const studentName = `学生${g + 1}${c + 1}${s + 1}`;
                const studentValue = getRandomIntBetween(
                    config.minStudentValue,
                    config.maxStudentValue
                );
                classData.children.push({
                    name: studentName,
                    value: studentValue,
                });
            }

            grade.children.push(classData);
        }

        schoolData.children.push(grade);
    }

    return schoolData;
}

function getRandomIntBetween(min: number, max: number): number {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}